#@adminLayout() #define main()

<link href="#(ctx)/static/ajax/libs/jquery-ztree/3.5/css/default/zTreeStyle.css" rel="stylesheet"/>
<script src="#(ctx)/static/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js"></script>

<body class="gray-bg">
	<div class="ui-layout-west">
		<div class="box box-main">
			<div class="box-header">
				<div class="box-title">
					<i class="fa icon-grid"></i>部门树
				</div>
				<div class="box-tools pull-right">
				   
					<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新栏目"><i class="fa fa-refresh"></i></button>
				</div>
				
				<select name="c_pro" id="c_pro" onchange="changeInfo()" class="form-control">
           		  #for(data: getOrgInfo(c_pro))
           		 	<option value="#(data.ccode)">#(data.cname)</option>
           		  #end
           		 </select>
			</div>
			<div class="ui-layout-content">
				<ul id="tree" class="ztree"></ul>
			</div>
		</div>
	</div>
	
	<div class="ui-layout-center">
		<div class="container-div">
			<div class="row">
				<div class="col-sm-12 search-collapse" id="searchbar">
					<form id="user-form">
						<div class="select-list">
							<ul> 
		                        <li>
		                     		 用户：<input type="text" name="cname" style="width:120px;"/>
									<input type="hidden" name="cdept" id="hf_dept"/>
									<input type="hidden" name="c_pro" id="hf_cpro"/>
		                        </li>
		                        
		                        <li>
		                            <a class="btn btn-primary btn-rounded btn-sm" onclick="doSearch()"><i class="fa fa-search"></i>&nbsp;搜索</a>
		                            <a class="btn btn-warning btn-rounded btn-sm" onclick="doReset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
		                        </li>
							</ul>
						</div>
					</form>
				</div>
				
		        <div class="btn-group-sm" id="toolbar" role="group">
		            <a class="btn btn-success" onclick="add()" id="btn_add">
		                <i class="fa fa-plus"></i> 新增
		            </a>
		            <a class="btn btn-primary single disabled" onclick="edit()"  id="btn_edit">
		                <i class="fa fa-edit"></i> 修改
		            </a>
		            <!-- <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
		                <i class="fa fa-remove"></i> 删除
		            </a>
		            <a class="btn btn-info" onclick="$.table.importExcel()">
					     <i class="fa fa-upload"></i> 导入
			        </a> -->
		            <a class="btn btn-warning" onclick="$.table.exportExcel()">
		                <i class="fa fa-download"></i> 导出
		            </a>
		        </div>
		        
		        <div class="col-sm-12 select-table table-bordered">
				    <table id="bootstrap-table" data-mobile-responsive="true"></table>
				</div>
			</div>
		</div>
	</div>
	
	<script type="text/javascript">
		var prefix = "#(ctx)/sysuser";
		
		$(function() {
			var panehHidden = false;
		    var west__size=220;
		    if ($(this).width() < 769) {
				panehHidden = true;
		    }
		    $('body').layout({ initClosed: panehHidden, west__size: west__size });

		    queryDeptTree();
		    queryList();
			
		});
		
		function queryList() {
		    var options = {
		        url: prefix + "/list",
	            createUrl: prefix + "/edit",
	            updateUrl: prefix + "/edit?ccode={id}",
	            removeUrl: prefix + "/remove",
	            exportUrl: prefix + "/export",
	            uniqueId: "ccode",
	            sortName: "cname",
	            sortOrder: "asc",
	            modalName: "用户",
	            rowStyle: function(row, index) {
	            	if (row.st_flag=='0') {
	                    return {
	                    	css: {
		                        background: '#DCDCDC'
		                    }
	                    }
	                }
	                return {
	                    css: {
	                        color: ''
	                    }
	                } 
	            },
	            columns: [{
	                checkbox: true
	            },{
						title: '序号',//标题  可不加,
	                    width:'50px',
						formatter: function (value, row, index) {
							return index+1;
						}
	             },
                {
                    title: '操作',
                    align: 'center',
                    width: '120px',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="edit(\'' + row.ccode + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        if(row.st_flag=='1'){
                            actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="opable(\'' + row.ccode + '\',0)"><i class="fa fa-file"></i> 禁用</a>');
                        }
                        else
                        {
                            actions.push('<a class="btn btn-primary btn-xs " href="javascript:void(0)" onclick="opable(\'' + row.ccode + '\',1)"><i class="fa fa-file"></i> 启用</a>');
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'user_num',
                    title: '登录名',
                    width:'100px'
                },
				{
                    field: 'cname',
                    title: '姓名',
                    width: '100px',
                    formatter: function(value, row, index) {
                        if(row.is_ld=='1')
                        {
                            return value+"<span style='color:red'>【主管】</span>";
                        }
                        else
                        {
                            return value;
                        }
                    }
                },
				{
                    field: 'user_pos',
                    title: '工作职位',
                    width: '100px'
                },
				{
                    field: 'cbm',
                    title: '所属部门',
                    width: '60px'
                },
				{
                    field: 'ctel',
                    title: '电话',
                    width: '100px'
                },
				{
                    field: 'cphone',
                    title: '手机',
                    width: '100px'
                },
				{
                    field: 'cemail',
                    title: '邮箱',
                    width: '100px'
                }]
		    };
		    $.table.init(options);
			
		    $("#bootstrap-table").colResizable({
				liveDrag:true, 
				gripInnerHtml:"<div class='grip'></div>", 
				draggingClass:"dragging", 
	            resizeMode:'overflow'
	        });
		}

		function doSearch()
		{
			queryDeptTree();
			$.table.search();
		}
		function doReset()
		{
			queryDeptTree();
			$.form.reset();
		}
		
		function changeInfo()
		{
			queryDeptTree();
			$.table.search();
		}
		
		function queryDeptTree()
		{
			var c_pro=$('#c_pro').val();
			$('#hf_cpro').val(c_pro);
			var url = prefix+"/getOrgTree?c_pro="+c_pro;
			var options = {
		        url: url,
		        expandLevel: 0,
		        onClick : zOnClick
		    };
			$.tree.init(options);
			
			function zOnClick(event, treeId, treeNode) {
				//点击树形结构最底栏目才能新增
				/*var zTree = $.fn.zTree.getZTreeObj(treeId);
				var nodes = zTree.getSelectedNodes();*/
				$('#hf_dept').val(treeNode.id);
				$.table.search();
			}
		}
		
		$('#btnExpand').click(function() {
			$._tree.expandAll(true);
		    $(this).hide();
		    $('#btnCollapse').show();
		});
		
		$('#btnCollapse').click(function() {
			$._tree.expandAll(false);
		    $(this).hide();
		    $('#btnExpand').show();
		});
		
		$('#btnRefresh').click(function() {
			queryDeptTree();
		});
		
		//切换启用禁用
		function opable(ccode,st_flag)
		{
			var msg="启用";
			if(st_flag=='0')
			{
				msg="禁用";
			}
			$.modal.confirm('是否'+msg,function(){
				var url=prefix+"/updateUser";
				$.operate.post(url,{ccode:ccode,cflag:st_flag,col:'st_flag'});
			});
		}
		
		function add()
		{
			var c_pro=$('#c_pro').val();
			if(c_pro!=''){
				$.modal.open("新增用户", prefix + "/edit?c_pro="+c_pro);
			}
			else
			{
				$.modal.alertError("请选择产权");
			}
		}
		function edit(ccode)
		{
			if(!ccode)
			{
				var rows = $.table.selectColumns("ccode");
	        	if (rows.length == 0) {
	        	    $.modal.alertWarning("请至少选择一条记录");
	        	    return;
	        	}
	        	ccode=rows[0];
			}
			var c_pro=$('#c_pro').val();
			if(c_pro!=''){
				$.modal.open("编辑用户", prefix + "/edit?ccode="+ccode+"&c_pro="+c_pro);
			}
			else
			{
				$.modal.alertError("请选择产权");
			}
		}
	</script>
</body>
#end